﻿<html>
  <header>
    <title>冀东水泥质检报告</title>
    <!-- <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script> -->
    <script src="./jweixin-1.6.0.js"></script>

    <script>
      // 设置签名
      function setConfig(params) {
        wx.config({
          // debug: true,
          appId: "wxec3dfc469a3b0a69", // 必须和当前网页的公众号一致
          timestamp: params.timestamp, // 后端生成
          nonceStr: params.nonceStr, // 后端生成
          signature: params.signature, // 后端生成
          // timestamp: "1761190301",
          // nonceStr: "733b852b-dbcb-44ad-a3f5-e43d7528d70f",
          // signature: "d68e0a5608267c9eeb5598b712cbbdc5a25f6d3b",
          jsApiList: [
            "invokeMiniProgramAPI",
            "navigateToMiniProgram",
            // "launchMiniProgram",
          ], // 必须声明该接口,
          openTagList: ["wx-open-launch-weapp"], // 必须添加这一行
        });
      }

      // 按钮1，根据search设置path属性
      function setPath(params) {
        let searchStr = location.search;
        const tmpEl = document.getElementById("launch-btn");
        tmpEl.setAttribute("path", "pages/index/open2" + searchStr);
      }

      // 按钮2，根据search获取schema
      function getSchema() {
        let searchStr = location.search;
        if (searchStr.startsWith("?")) {
          searchStr = searchStr.substring(1);
        }
        return fetch("https://zlyz.jdsn.cn/t/sysOperationLog/getSchema", {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
          },
          body: JSON.stringify({
            jump_wxa: {
              path: "/pages/index/open2",
              query: searchStr,
              // release trial develop
              // env_version: "release",
            },
          }),
        });
      }

      // 按钮1，根据href获取签名
      function getConfig() {
        const getSignUrl =
          "https://zlyz.jdsn.cn/t/sysOperationLog/getSign?url=" + location.href;
        fetch(getSignUrl).then((res) => {
          const bbb = res.json().then((json) => {
            if (json.success) {
              setConfig(json.result);
            }
          });
        });
      }

      // 页面加载完成后尝试跳转
      window.onload = function () {
        const ua = navigator.userAgent.toLowerCase();
        if (/micromessenger/.test(ua)) {
          // 微信环境
          // 给第一个按钮用
          getConfig();
          // setConfig();
          setPath();

          // 隐藏第二个按钮
          const tmpEl = document.getElementById("other-plat-outer");
          tmpEl.style.display = "none";
        } else {
          // 隐藏第一个按钮
          const tmpEl = document.getElementById("wx-plat-outer");
          tmpEl.style.display = "none";
          // 其他环境
          // 给第二个按钮用
          getSchema().then((res) => {
            const bbb = res.json().then((json) => {
              const weappScheme = json.result.openlink;
              // const weappScheme = "weixin://dl/business/?t=YvjJ8XzopSj";
              const tmpEl = document.getElementById("gotoBtn");
              tmpEl.addEventListener("click", function (params) {
                window.location.href = weappScheme;
              });
            });
          });
        }
      };

      // 验证是否初始化成功
      wx.ready(function () {
        console.log("JS-SDK 初始化成功！");
      });

      wx.error(function (err) {
        console.error("JS-SDK 初始化失败:", err);
      });
    </script>

    <style>
      .content-outer {
        display: flex;
        align-items: center;
        height: calc(100vh - 4px);
        width: calc(100vw - 4px);
      }
      .region-outer {
        display: flex;
        justify-content: center;
        padding: 12px;
        padding-bottom: 60px;
        /* border: #ccc 1px solid; */
        width: 100%;
      }

      .goto-btn {
        padding: 12px 20px;
        border: #ccc 1px solid;
        font-size: 40px;
        border-radius: 8px;
        background-color: #07c160;
        color: #fff;
        white-space: nowrap;
      }
    </style>
  </header>
  <body>
    <div class="content-outer">
      <div id="wx-plat-outer" class="region-outer" style="margin-bottom: 12px">
        <wx-open-launch-weapp
          id="launch-btn"
          appid="wx2ce68e029e5f4b5f"
          username="gh_26e8fea4c5d3"
          path="pages/index/open2"
        >
          <script type="text/wxtag-template">
            <style>
              .goto-btn {
                padding: 12px 20px;
                border: #ccc 1px solid;
                font-size: 40px;
                border-radius: 8px;
                background-color: #07c160;
                color: #fff;
                white-space: nowrap;
                width: auto;
              }
            </style>
            <div class="goto-btn">
              即将打开小程序
            </div>
          </script>
        </wx-open-launch-weapp>
      </div>
      <div id="other-plat-outer" class="region-outer">
        <div id="gotoBtn" class="goto-btn">即将打开小程序</div>
      </div>
    </div>
  </body>
</html>
